<template>
  <div>
       <el-table
    :data="this.replyList"
    style="width: 100%">
    <!-- <el-table-column
      label="用户"
      width="180">
        <template slot-scope="scope">
            <img style="width:50px;height:50px" :src="'/api/upload/'+scope.row.userHeader">
      </template>
    </el-table-column> -->
    <el-table-column
      label="用户名"
      width="180"
      prop="cuser"
      >
     
    </el-table-column>
    <el-table-column
      label="内容"
      width="180"
      prop="cinfo"
      >
     
    </el-table-column>
    <el-table-column
      label="点赞数"
      width="180"
      prop="cstar"
      >
     
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <!-- <el-button
          size="mini"
           @click="like(scope.row.id)">点赞</el-button> -->
        <img src="../assets/zan.png" v-if="this.find" @click="dianzan(scope.row.id)">
        <img src="../assets/budianzzan.png" v-if="this.find" @click="quxiao(scope.row.id)">
      </template>
    </el-table-column>
  </el-table>
  </div>
</template>

<script>
import ajax from "../service/ajax.js"
import { mapState } from 'vuex';
import {quxiao} from "../service/user"
export default {
 data() {
    return {
      replyList:{},
      userComment:{},
    };
  },
  created(){
        this.findAll();
       
       // this.setUsers();
    },
    computed:{
        ...mapState("user",["users","pagination"])
    },
    methods: {
      async findAll(){
       //alert(1)
        var info = await ajax.getSubmit("/api/comments")
        //alert(JSON.stringify(info))
         if(info.status == "1"){
               this.replyList = info.data
               //alert(JSON.stringify(this.replyList))
            }
   
      },
      // 判断是否点过赞
      async find(){
          //得到登录用户的id
          this.userComment.userId = "";
          this.userComment.commentsId = scope.row.id;
          var info = await ajax.getSubmit("/api/userComments",this.userComment)
          if(info.data != null){
            return true;
          }
          return false;
      },
      async dianzan(id){
         //得到登录用户的id
          this.userComment.userId = "";
          this.userComment.commentsId = scope.row.id;
        var info  = await ajax.postSubmit("/api/userComments",this.userComment)
        if(info.data == 'ok'){
            this.findAll();
        }
      },
      async quxiao(id){
        let info = await quxiao(id);
        if(info == 'ok'){
          this.findAll()
        }
      }

    },
}
</script>

<style>

</style>